package com.wenhui.schoolyardinfo.mine.ui;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qmuiteam.qmui.widget.QMUILoadingView;
import com.qmuiteam.qmui.widget.QMUITopBar;
import com.wenhui.schoolyardinfo.R;
import com.wenhui.schoolyardinfo.base.BaseActivity;
import com.wenhui.schoolyardinfo.base.BaseMvpActivity;
import com.wenhui.schoolyardinfo.callback.RcvOnItemViewClickListener;
import com.wenhui.schoolyardinfo.firstpage.bean.MineAlbumBean;
import com.wenhui.schoolyardinfo.firstpage.bean.PhotoBean;
import com.wenhui.schoolyardinfo.login.view.base.IBaseView;
import com.wenhui.schoolyardinfo.mine.adapter.MineAlbumAdapter;
import com.wenhui.schoolyardinfo.mine.presenter.MinePresenterImpl;
import com.wenhui.schoolyardinfo.mine.view.IMineAlbumView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * author    : Urasaki
 * e-mail    : 1164688204@qq.com
 * date      : 2019/7/6 09:50
 * introduce :
 */

public class MineAlbumActivity extends BaseMvpActivity<IBaseView, MinePresenterImpl>
        implements RcvOnItemViewClickListener, IMineAlbumView {

    private static final String TAG = "MineAlbumActivity";
    @BindView(R.id.imv_back)
    ImageView imvBack;
    @BindView(R.id.layout_back)
    RelativeLayout layoutBack;
    @BindView(R.id.tev_title)
    TextView tevTitle;
    @BindView(R.id.topbar)
    QMUITopBar topbar;
    @BindView(R.id.mine_album_recycler_view)
    RecyclerView mineAlbumRecyclerView;
    private QMUILoadingView loadView;

    private MineAlbumAdapter mineAlbumAdapter;
    private GridLayoutManager layoutManager;
    private List<PhotoBean> photoBeanList;
    private List<String> photoAlbumUrl2List;
    private List<MineAlbumBean> mineAlbumBeanList;

    private Map<String, String> bodyParams;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine_album);
        ButterKnife.bind(this);

        initData();
        initViews();
    }

    @Override
    protected void initData() {
        photoBeanList = new ArrayList<>();
        photoAlbumUrl2List = new ArrayList<>();
        mineAlbumBeanList = new ArrayList<>();

        photoBeanList.add(new PhotoBean(0, "校园", "https://ws1.sinaimg.cn/large/0065oQSqly1fuh5fsvlqcj30sg10onjk.jpg", false));
        photoBeanList.add(new PhotoBean(0, "校园", "https://ws1.sinaimg.cn/large/0065oQSqly1fuh5fsvlqcj30sg10onjk.jpg", false));
        photoBeanList.add(new PhotoBean(0, "校园", "https://ws1.sinaimg.cn/large/0065oQSqly1fuh5fsvlqcj30sg10onjk.jpg", false));
        photoBeanList.add(new PhotoBean(0, "校园", "https://ws1.sinaimg.cn/large/0065oQSqly1fuh5fsvlqcj30sg10onjk.jpg", false));
        photoBeanList.add(new PhotoBean(0, "校园", "https://ws1.sinaimg.cn/large/0065oQSqly1fuh5fsvlqcj30sg10onjk.jpg", false));
        photoBeanList.add(new PhotoBean(0, "校园", "https://ws1.sinaimg.cn/large/0065oQSqly1fuh5fsvlqcj30sg10onjk.jpg", false));


        mineAlbumBeanList.add(new MineAlbumBean("隆美尔上将相册", 199,
                photoBeanList, "所有人可见"));
        mineAlbumBeanList.add(new MineAlbumBean("隆美尔上将相册", 199,
                photoBeanList, "所有人可见"));
        mineAlbumBeanList.add(new MineAlbumBean("隆美尔上将相册", 199,
                photoBeanList, "所有人可见"));
        mineAlbumBeanList.add(new MineAlbumBean("隆美尔上将相册", 199,
                photoBeanList, "所有人可见"));
        mineAlbumBeanList.add(new MineAlbumBean("隆美尔上将相册", 199,
                photoBeanList, "所有人可见"));
        mineAlbumBeanList.add(new MineAlbumBean("隆美尔上将相册", 199,
                photoBeanList, "所有人可见"));

        loadView = new QMUILoadingView(this);
        loadView.setVisibility(View.GONE);
        loadView.setSize(120);

        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
        layoutParams.gravity = Gravity.CENTER;
        addContentView(loadView, layoutParams);

        bodyParams = new HashMap<>();
        bodyParams.put("", "");
        bodyParams.put("", "");
        presenter = initPresenter();
//        presenter.getMineAlbum(bodyParams);
    }

    @Override
    protected void initViews() {
        setTopBar(topbar);

        initAdapter();
    }

    @Override
    protected MinePresenterImpl initPresenter() {
        return new MinePresenterImpl(this, this);
    }

    private void initAdapter() {
        layoutManager = new GridLayoutManager(this, 2);
        layoutManager.setOrientation(OrientationHelper.VERTICAL);
        mineAlbumRecyclerView.setLayoutManager(layoutManager);
        mineAlbumRecyclerView.setItemAnimator(new DefaultItemAnimator());
//        mineAlbumRecyclerView.addItemDecoration(new RecyclerViewDivider(
//                this,
//                LinearLayoutManager.VERTICAL,
//                ScreenManager.dipTopx(this, 1),
//                getResources().getColor(R.color.colorGrayB)));

        mineAlbumAdapter = new MineAlbumAdapter(this);
        mineAlbumRecyclerView.setAdapter(mineAlbumAdapter);
        mineAlbumAdapter.setRcvOnItemViewClickListener(this);

        mineAlbumAdapter.clearData();
        mineAlbumAdapter.addAllData(mineAlbumBeanList);
    }

    @Override
    public void showLoading() {
        loadView.setVisibility(View.VISIBLE);
        loadView.start();
    }

    @Override
    public void hideLoading() {
        loadView.stop();
        loadView.setVisibility(View.GONE);
    }

    @Override
    public void getMineAlbumSuccess(String success) {

    }

    @Override
    public void getMineAlbumError(String error) {

    }

    @Override
    public void onItemClickListener(int position, View view) {
        switch (view.getId()) {
            case R.id.layout_new_album:
                showToast("layout_new_album");
                startActivity(NewAlbumActivity.class);
                break;
            case R.id.imv_photo_album:
                showToast("imv_photo_album");
                startActivity(AlbumActivity.class);
                break;
            default:
                break;
        }
    }

    @OnClick(R.id.layout_back)
    public void onViewClicked() {
        finish();
    }

}
